local SelectHandler = require('core_alpha_rts/main/select_handler')
local HT = require('core_alpha_rts/main/select_handle_tools')

local function FixTargetPoint(x, z)
    local offset_distance = 2 -- 偏移距离可以根据需要调整

    local angle = math.random() * 2 * math.pi

    local offset_x = offset_distance * math.cos(angle)
    local offset_z = offset_distance * math.sin(angle)

    return x + offset_x, z + offset_z
end

TheInput:AddMouseButtonHandler(function(button, down, x, y)
    if button == 1001 and down and TheInput:IsKeyDown(KEY_CTRL) then
        local mouse_x,_,mouse_z = ConsoleWorldPosition():Get()
        local mouseover = TheInput:GetWorldEntityUnderMouse()
        local mouseoverguid = mouseover and mouseover.GUID or nil
        SendModRPCToServer(MOD_RPC['alpha_rts']["control_unit_move"],mouse_x,mouse_z,mouseoverguid)
    end
end)

AddModRPCHandler("alpha_rts","control_unit_move", function(player, mouse_x,mouse_z,mouseoverguid)
    if player and player.alpha_rts_selected_ent then
        for _,ent in ipairs(player.alpha_rts_selected_ent or {}) do
            if S_ALPHA_RTS:checkAlive(ent) then
                if ent.components.locomotor then
                    ---@class ent
                    ---@field alpha_rts_line nil|ent # rts框选 方向命令指示线
                end
            end
        end

        SelectHandler:HandleSelect(player, mouse_x,mouse_z,mouseoverguid)
    end
end)
